package cassandrawindow;
import org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS;
import org.apache.commons.dbcp.datasources.SharedPoolDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class ConnectionPool {
    private  DataSource ds;
    
    public ConnectionPool(String urlMySQL,String username,String pass)
    {
        DriverAdapterCPDS cpds = new DriverAdapterCPDS();
        try {
            cpds.setDriver("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        cpds.setUrl(urlMySQL);
        cpds.setUser(username);
        cpds.setPassword(pass);
        
        SharedPoolDataSource tds = new SharedPoolDataSource();
        tds.setConnectionPoolDataSource(cpds);
        tds.setMaxActive(10);
        tds.setMaxWait(50);
        tds.setMinEvictableIdleTimeMillis(30000);        
        ds = tds;        
    }

    public  Connection getConnection() throws SQLException {
        return ds.getConnection();
    }

}
